package huv.andlogin;

import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.widget.Toast;

public class WifiControl extends BroadcastReceiver {
	WifiManager _wm;
	andlogin _father;
	NetworkInfo _ni;
	public WifiControl(andlogin f){
		_father = f;
		_wm = (WifiManager) _father.getSystemService(Context.WIFI_SERVICE);
	}
	@Override
	public void onReceive(Context arg0, Intent arg1) {
		// TODO Auto-generated method stub
		if(_wm.getConnectionInfo().getSSID()==null){
			return; 
		}
		Cfg t = _father.cfgp.findSSID(_wm.getConnectionInfo().getSSID()); 
		if(t!=null){
			Toast toast2 = Toast.makeText(arg0, "Connecting...",Toast.LENGTH_SHORT);
			toast2.show();
			int state = AutoLogin.login(t);
			String msg="";
			switch(state){
				case AutoLogin._CONNECTION_COMPLETE: msg = "Connection Complete"; break;
				case AutoLogin._INVALID_URL: msg = "Invalid URL"; break;
				case AutoLogin._IO_ERROR: msg = "IO Error"; break;
				case AutoLogin._KEY_MANAGMENT_ERROR: msg = "Key Management Error"; break;
				case AutoLogin._NO_SUCH_ALGORITHM: msg = "No such Algorithm"; break;
				case AutoLogin._PROTOCOL_ERROR: msg = "Protocol Error"; break;
				case AutoLogin._CONNECTION_CLOSE_ERROR: msg = "Protocol Error"; break;
				case AutoLogin._DATA_OUTPUT_STREAM_INIT_ERROR: msg = "Data Output Stream Error"; break;
				case AutoLogin._WRITE_BYTE_ERROR: msg = "Write Bytes Error"; break;
				case AutoLogin._UNABLE_OPEN_CONNECTION: msg = "Unable to open Connection"; break;
				default: msg= "oh cazzo"; break;
			}
			Toast toast = Toast.makeText(arg0, msg,Toast.LENGTH_SHORT);
			toast.show();
		}
	}

}
